#coding=utf-8
def insertLlist(L,x):
    if x > L[len(L)-1]:
        L.append(x)
        return L
    else:
        for i in range(0,len(L)):
            if x < L[i]:
                L.insert(i,x)
                break
        return L
list4 = [1,3,5,6,7]
print insertLlist(list4,4)


def calAvg(L):
    """
    计算平均分
    :param L:
    :return:avg_score
    """
    sum = 0
    count = 0
    for score in L:
        sum += score
        count += 1
    avg_score = int(sum / count)
    return avg_score


def scoreAvg(filename):
    """
    定义函数calAvg()，计算某一门课程的平均分（函数参数为某门课成绩对应的 列表名，返回值为该门课的平均分）
    :param filename:
    :return:
    """

    f = open(filename)
    a = f.readlines()
    l1 = []
    l2 = []
    for line in a:
        line = line.strip()
        l3 = line.split()
        l1.append(int(l3[1]))
        l2.append(int(l3[2]))
    f.close()


    print("课程一的平均分为：", calAvg(l1))
    print("课程二的平均分为：", calAvg(l2))

scoreAvg("score.txt")

def getodd(args):
    """
    检查获取传入列表或元组对象的所有奇数位索引对应的元素，并将其作为新列表返回给调用者 by yanping.zhang
    :param args:
    :return: result or exception_string
    """
   # result = []
    if isinstance(args,(list,tuple)):

        ret = []
        for i in range(len(args)):
            if i % 2 == 1:
                ret.append(args[i])
            else:
                pass
        return ret
    else:
        return exception_string
list2 = [1,33,4,5,76,7,8]

print getodd(list2)

def a3(arg):
    ret = [ ]
    for i in range(len(arg)):
        if i % 2 == 1:
            ret.append(arg[i])
        else:
            pass
    return ret
li = [11,22,33,44,55]
r = a3(li)
print(li)
print(r)